package com.egao.common.publicly;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.company.entity.Recruit;
import com.egao.common.module.outer.entity.OuterPreach;
import com.egao.common.publicly.entity.PubliclyCareerVO;
import com.egao.common.publicly.service.PubliclyOuterPreachService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 校外宣讲会
 * @author pyx
 */
@Api(tags = "校外宣讲会")
@RestController
@RequestMapping("${api}")
public class PubliclyOuterPreachController {
    @Autowired
    private PubliclyOuterPreachService publiclyOuterPreachService;

    @ApiOperation("列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = false, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页条数", required = false, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "title", value = "标题", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "companyName", value = "举办方", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "holdTime", value = "举办时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "holdAddress", value = "举办地点", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "时间是否已过，0否，1是", required = false, dataType = "Integer", paramType = "query"),
    })
    @GetMapping("/publicly/outer/preach/list")
    public PageResult<PubliclyCareerVO> list(HttpServletRequest request){
        PageParam<PubliclyCareerVO> pageParam = new PageParam<>(request);
        return new PageResult<>(publiclyOuterPreachService.listPage(pageParam),pageParam.getTotal());
    }

    @ApiOperation("详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "query"),
    })
    @OperLog(value = "校外宣讲会", desc = "查询详情")
    @GetMapping("/publicly/outer/preach/get")
    public JsonResult get(Integer id){
        if(id == null){
            return JsonResult.error("没有找到相应信息");
        }

        OuterPreach outerPreach = publiclyOuterPreachService.getId(id);
        if(outerPreach == null){
            return JsonResult.ok("校外宣讲会不存在");
        }

        return JsonResult.ok().setData(outerPreach);
    }
}
